package com.hci.mercatinidinatale;

import java.io.IOException;
import java.io.InputStream;

import com.hci.mercatinidinatale.db.Mercatino;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class InfoMercatino extends Activity implements OnClickListener
{

	Mercatino mercatino;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_info_mercatino);
		Intent i = getIntent();
		
		mercatino = (Mercatino)i.getSerializableExtra("mercatino");
		
		Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/AbyssinicaSIL-R.ttf");
		TextView txtInfoTitle = (TextView)findViewById(R.id.txtInfoTitle);
		TextView txtInfoLink = (TextView)findViewById(R.id.txtInfoLink);
		ImageView imgInfoFoto = (ImageView)findViewById(R.id.imgInfoFoto);
		Button btnInfoRicercaAlloggio = (Button)findViewById(R.id.btnInfoRicercaAlloggio);
		
		txtInfoTitle.setTypeface(tf);
		txtInfoTitle.setText(mercatino.getNome());
		btnInfoRicercaAlloggio.setOnClickListener(this);
		
		txtInfoLink.setText(Html.fromHtml("<a href=" + "http://" + mercatino.getLink() + ">" + mercatino.getLink()));
		txtInfoLink.setMovementMethod(LinkMovementMethod.getInstance());
		InputStream is = null;
		try
		{
			is = getAssets().open("foto/"+mercatino.getFoto());
			Drawable d = Drawable.createFromStream(is, null);
			imgInfoFoto.setImageDrawable(d);
		}
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try
			{
				is.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		
	}

	@Override
	public void onClick(View v)
	{
		Intent i = new Intent(this, RicercaAlloggio.class);
		i.putExtra("mercatino", mercatino);
		startActivity(i);
	}

}
